const app = getApp<IAppOption>()

Page({
  data: {
    swiperList: [],
    menu: [{
      title: '号码归属地',
      name: 'phone',
      color: 'cyan',
      icon: 'phone'
    },{
      title: 'IP地址',
      name: 'ip',
      color: 'blue',
      icon: 'IP'
    }]
  },
  onLoad() {
    app.$request('toutiao', {
      type: "yule"
    }).then((res: any) => {
      let swiperList: any = res.data.map((newItem: any): any => {
        if (newItem.thumbnail_pic_s) {
          return {
            title: newItem.title,
            url: newItem.url,
            img: newItem.thumbnail_pic_s
          }
        }
      })
      swiperList = swiperList.splice(0, 4)
      this.setData({
        swiperList: swiperList
      })
    })
  },
  previewImg(event: any) {
    let currentUrl = event.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl,
      urls: this.data.swiperList.map((newItem: any) => newItem.img)
    })
  },
  menuClickHandle(event: any) {
    let name = event.currentTarget.dataset.name
    wx.navigateTo({
      url: `/pages/${name}/${name}`
    })
  }
})